package partes_GUI.Stats_GUI;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JTextField;

import partes_GUI.NumListener;

public abstract class StatTF extends JTextField{
	
	protected class StatListener implements KeyListener{

		public void keyPressed(KeyEvent arg0) {
			}

		public void keyReleased(KeyEvent arg0) {
			if (ssb!=null)
				if (arg0.getKeyChar()=='\b')
					ssb.setValue(0);
				else
					ssb.setValue(Integer.parseInt(getText()));
		}

		public void keyTyped(KeyEvent arg0) {
			}
	}
	private static final long serialVersionUID = 3874790011250992071L;
	
	protected int ancho;
	protected int alto;
	protected StatScrollBar ssb;
	
	public StatTF(int ancho, int alto, boolean LigadoScroll){
		super();
		this.addKeyListener(new NumListener());
		if(LigadoScroll)
			this.addKeyListener(new StatListener());
		this.ancho=ancho;
		this.alto=alto;
		this.setText("0");
	}
	
	public void ubicar(int x, int y){
		this.setBounds(x,y, ancho, alto);
	}
	
	public int getAncho(){
		return ancho;
	}
	
	public int getAlto(){
		return alto;
	}
	
	public void setSSB(StatScrollBar ssb){
		this.ssb=ssb;
	}
	
	public abstract void actualizar();
	
}
